Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

starter boilerplate #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

starter boilerplate #2

wants to merge 1 commit into from

Conversation

kraschtest
Copy link

################### FONCTIONS

############## CRÉER UN RÉSEAU

def results_hash ( votes ):
"" " Compter les votes par candidat et par mention
Renvoie une dictée de noms de candidats contenant des tableaux de votes.
"" "
candidats_results = {
candidat: [ 0 ] * len ( MENTIONS )
pour candidat en CANDIDATS .keys ()
}
pour vote en votes:
pour le candidat, mentionner dans vote.items ():
candidats_résultats [candidat] [mention] + = 1
retour candidats_résultats

############## CALCULER MEDIAN

def majoritary_mentions_hash ( candidats_résultats ):
r = {}
pour candidat, candidate_result dans candidats_results.items ():
cumulated_votes = 0
pour mention, vote_count en énumérer (candidate_result):
cumulated_votes + = vote_count
si MEDIAN < cumulated_votes :
r [candidat] = {
" mention " : mention,
" score " : cumulated_votes
}
Pause
retour r

############## TRIER LES CANDIDATS

def sort_candidates_by ( mentionne ):
# # tri des bulles c'est parti!
unsorted = [(key, (mention [ " mention " ], mention [ " score " ])) pour key, mention dans mentions.items ()]
swapped = True
pendant l' échange:
swapped = False
pour j dans la plage ( 0 , len (non trié) - 1 ):
# # mais nous avons besoin d'un tri à bulle INVERSE ;-)
# (notez qu'ici nous comparons les tuples, ce qui est plutôt soigné)
si non trié [j + 1 ] [ 1 ] > non trié [j] [ 1 ]:
non trié [j + 1 ], non trié [j] = non trié [j], non trié [j + 1 ]
swapped = True

retour [
    {
        " nom " : candidat [ 0 ],
        " mention " : candidat [ 1 ] [ 0 ],
        " score " : candidat [ 1 ] [ 1 ],
    }
    pour candidat en non trié
]

############## FORMAT RÉSULTATS

def print_results ( résultats ):
pour i, résultat en énumérer (résultats):
nom = CANDIDATS [résultat [ " nom " ]]
mention = MENTIONS [résultat [ " mention " ]]
score = résultat [ " score " ] * 100 . / VOTES
si i == 0 :
print ( " Gagnant: {} avec { : .2f } % d e mentionne {} ou réduit " .format (
nom, score, mention
))
continuer
sinon :
print ( " - {} avec { : .2f } % d e mentionne {} ou malgré " .format (
nom, score, mention
))

Votre code va ici

@@ -128,10 +57,6 @@ def print_results (résultats):

def main ():
votes = create_votes ()
results = results_hash (votes)
majoritary_mentions = majoritary_mentions_hash (résultats)
sorted_candidates = sort_candidates_by (majoritary_mentions)
print_results (sorted_candidates)

si name == ' main ' :
principale()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants